package com.jy.adscm.zltx.controller;


import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.zltx.bean.Maai_production;
import com.jy.adscm.zltx.service.Maai_productionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yyy
 * @since 2018-10-15
 */
@RestController
@RequestMapping("/adscm/zltx/maai_production")
public class Maai_productionController {
    @Autowired
    Maai_productionService maai_productionService;
    @Autowired
    RedisTemplate <Object, Token> tokenRedisTemplate;
    /**
     * 添加现场指导原则内容
     * @param production
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/insertContent/{orgId}")
    public SimpleCoreResponse insertContent(@PathVariable String orgId, Maai_production production) throws AdscmSystemException {
        production.setId(UUID.randomUUID().toString());
           /* Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(production.getInputperson(), tokenRedisTemplate);
            if (token.getUser().getName()!=null&&!"".equals(token.getUser().getName())){
                production.setInputperson(token.getUser().getName());
            }*/
        System.out.println(production.getInputtime());
        return new SimpleCoreResponse("200","成功添加数据",maai_productionService.insert(production));
    }


    /**
     * 根据id删除现场指导原则数据
     * @param id
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/deleteContent/{orgId}")
    public  SimpleCoreResponse deleteContent(@PathVariable String orgId,String id) throws  AdscmSystemException{

        return new SimpleCoreResponse("200","成功删除数据",maai_productionService.deleteById(id));
    }

    /**
     * 根据id修改现场指导原则数据
     * @param production
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/updateContent/{orgId}")
    public SimpleCoreResponse updateContent(@PathVariable String orgId,Maai_production production) throws AdscmSystemException{

        return new SimpleCoreResponse("200","成功修改数据", maai_productionService.updateById(production));
    }

    /**
     * 根据菜单id查询现场指导原则
     * @param orgId
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/queryProduction/{orgId}")
    public SimpleCoreResponse queryProduction(@PathVariable String orgId) throws AdscmSystemException{
        return new SimpleCoreResponse("200","查询成功",maai_productionService.loadByOrgid(orgId));

    }

    /**
     * 模糊查询内容
     * @param nums
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/searchAllCondition/{orgId}")
    public SimpleCoreResponse searchAllCondition(@PathVariable String orgId,String nums,String orgid) throws AdscmSystemException{
        return new SimpleCoreResponse("200","查询成功",maai_productionService.searchAllCondition(nums,orgid));
    }
}

